home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / Delphi 3.0 / DATA.Z / dsintf.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-01-29  |  19.0 KB  |  561 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Visual Component Library                 }
  5. {       DataSet Interface Unit                          }
  6. {                                                       }
  7. {       Copyright (c) 1997 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit DSIntf;
  12.  
  13. {$MINENUMSIZE 4}
  14.  
  15. interface
  16.  
  17. uses BDE, Windows;
  18.  
  19. const
  20.   dsRecOrg           = $0001;       // Original record (was changed)
  21.   dsRecDeleted       = $0002;
  22.   dsRecNew           = $0004;
  23.   dsRecModified      = $0008;       // Record was changed
  24. //  dsRecent           = $0010;       // Most recent version of a changed record (visible)
  25.   dsUnused           = $0020;       // Not used anymore
  26.  
  27.   dsISNOTVISIBLE     = dsRecDeleted or dsRecOrg or dsUnused;
  28.   dsISVISIBLE        = not (dsRecDeleted or dsRecOrg or dsUnused);
  29. //  dsCHANGED          = dsRecDeleted or dsRecNew or dsRecModified or dsRecOrg;
  30.  
  31.  
  32. // Additional fieldtypes
  33.   fldINT8               = $1001;
  34.   fldUINT8              = $1002;
  35.   fldBOOL8              = $1003;
  36.   fldBOOL16             = fldBOOL;
  37.   fldBOOL32             = $1004;
  38.   fldINT64              = $1005;
  39.   fldUINT64             = $1006;
  40.   fldUNICODE            = $1007;
  41.  
  42.   MAXFIELDLEN        = 256;
  43.   MAXKEYFIELDS       = 16;
  44.  
  45.  
  46. type
  47.  
  48.   DSAttr = Byte;
  49.   pDSAttr = ^DSAttr;
  50.  
  51.   DSKEY = packed array[0..DBIMAXFLDSINKEY-1] of Integer;
  52.   DSKEYBOOL = packed array[0..DBIMAXFLDSINKEY-1] of Bool;
  53.  
  54.   hDSFilter = Pointer;
  55.   phDSFilter = ^hDSFilter;
  56.  
  57.   hDSAggregate = Integer;
  58.   phDSAggregate = ^hDSAggregate;
  59.  
  60.   DSRECNUM = Longint;               // 1-based record number. 0 and negative might have special meaning
  61.   DSSEQNUM = Integer;               // 1-base sequence number of record. 0 means undefined.
  62.  
  63. type
  64.   DSShareMode = (                   // Database/Table Share type
  65.     dsOPENSHARED,                   // Open shared  (Default)
  66.     dsOPENEXCL                      // Open exclusive
  67.   );
  68.  
  69.   DSOpenMode = (                    // Database/Table Access type
  70.     dsREADWRITE,                    // Read + Write   (Default)
  71.     dsREADONLY                      // Read only
  72.   );
  73.  
  74.   BOOKMRK = Pointer;
  75.   pBOOKMRK = ^BOOKMRK;
  76.  
  77.   pDSBOOKMRK = ^DSBOOKMRK;
  78.   DSBOOKMRK = packed record
  79.     iPos   : Integer;               // Position in given order
  80.     iState : Integer;               // State of cursor
  81.     iRecNo : Integer;               // Record number
  82.     iSeqNo : Integer;               // Version number of order
  83.     iOrderID : Integer;             // Defines Order
  84.   end;
  85.  
  86. const
  87.   BOOKMARKSIZE     = sizeof(DSBOOKMRK);
  88.  
  89. type
  90.   DSProp = ( 
  91.     dspropLOGCHANGES,            // rw BOOL(TRUE), logs changes for undo/delta
  92.     dspropREADONLY,              // rw BOOL(TRUE), cannot update dataset (is NOT stored with dataset,-use AddOptParameter)
  93.     dspropNOOFCHANGES,           // r  UINT32, number of (compressed) changes (m/i/d)
  94.     dspropCONSTRAINTS_DISABLED,  // rw BOOL(TRUE), constraints are disabled (insert/modify/delete)
  95.     dspropDSISPARTIAL            // r BOOL(TRUE), Dataset is not yet complete (async. mode)
  96.   );
  97.  
  98.   CURProp = (
  99.     curpropCONSTRAINT_ERROR_MESSAGE             // r pCHAR (returns POINTER to string, not string itself)
  100.   );
  101.  
  102. const
  103.   fldstUNKNOWN       = 255;
  104.  
  105. // Misc. alchemy error-messages
  106. const
  107.   ERRCAT_ALC          = $40;
  108.   ERRBASE_ALC         = $4000;
  109.  
  110.   ERRCODE_DELTAISEMPTY       = 1; // Delta is empty.
  111.   ERRCODE_NOTHINGTOUNDO      = 2; // Nothing to undo
  112.  
  113.   DBIERR_DELTAISEMPTY       = ERRBASE_ALC + ERRCODE_DELTAISEMPTY;
  114.   DBIERR_NOTHINGTOUNDO      = ERRBASE_ALC + ERRCODE_NOTHINGTOUNDO;
  115.   { !!! Add missing ones here from AlcTypes. }
  116.  
  117.   BLANK_NULL           = 1;       // 'real' NULL
  118.   BLANK_NOTCHANGED     = 2;       // Not changed , compared to original value
  119.  
  120. type
  121.  
  122. { Field Descriptor }
  123.  
  124.   pDSFLDDesc = ^DSFLDDesc;
  125.   DSFLDDesc = packed record
  126.     szName          : DBINAME;      // Field name
  127.     iFldType        : Integer;      // Field type
  128.     iFldSubType     : Integer;      // Field subtype (if applicable)
  129.     iUnits1         : Integer;      // Number of Chars, precision etc
  130.     iUnits2         : Integer;      // Decimal places etc.
  131.     iFldLen         : Integer;      // Length in bytes (computed)
  132.     iFldOffsInRec   : Integer;      // Offset to field  in record buffer
  133.     iNullOffsInRec  : Integer;      // Offset to null flag (1byte) in record buffer
  134.     bHidden         : Bool;         // Field is a hidden field
  135.     bCalculated     : Bool;         //
  136.     bReadOnly       : Bool;         // Field is not updatetable
  137.     iOptParameters  : Integer;      // Number of optional parameters for field
  138.   end;
  139.  
  140. {  Index descriptor }
  141.  
  142.   pDSIDXDesc = ^DSIDXDesc;
  143.   DSIDXDesc = packed record
  144.     szName    : DBINAME;            // IndexName
  145.     iFields   : Integer;            // Number of fields in order (0 -> base order)
  146.     iKeyFields: DSKEY;              // FieldNumbers
  147.     iKeyLen   : Integer;            // Total length of key (computed)
  148.     bUnique   : Bool;
  149.     bDescending  : DSKEYBOOL;       // TRUE ->Descending
  150.     bCaseInsensitive : DSKEYBOOL;
  151.   end;
  152.  
  153. { Cursor Properties }
  154.  
  155.   pDSProps = ^DSProps;
  156.   DSProps = packed record
  157.     szName           : DBIPATH;      // Name, if any
  158.     iFields          : Integer;      // Number of columns
  159.     iRecBufSize      : Integer;      // Size of record buffer
  160.     iBookMarkSize    : Integer;      // Size of bookmark
  161.     bReadOnly        : Bool;         // Dataset is not updateable
  162.     iIndexes         : Integer;      // Number of indexes on dataset
  163.     iOptParams       : Integer;      // Number of optional parameters
  164.     bDelta           : Bool;         // This is a delta dataset
  165.     iLCID            : Integer;      // Language used
  166.     iUnused          : packed array[0..7] of Integer; // Reserved
  167.   end;
  168.  
  169. type
  170. // Change Notification callback
  171.   pfCHANGECallBack = procedure(           // Call-back funtion pntr type
  172.     iClientData  : Integer                  // Client callback data
  173.   ); stdcall;
  174.  
  175. // Filter callback
  176. type
  177.   pfDSFilter = function(
  178.     iClientData  : Integer;
  179.     pRecBuf      : PChar
  180.   ): Bool; stdcall;
  181.  
  182. // Calculated field callback
  183. type
  184.   pfDSCalcField = function(
  185.     iClientData  : Integer;
  186.     pRecBuf      : PChar            // Current record-buffer
  187.   ): DBIResult; stdcall;
  188.  
  189. // Resolver & Reconcile callback return values
  190. const
  191.   dscbrSKIP          = 1;   { Skip this operation (resolver : report error). }
  192.   dscbrABORT         = 2;   { Abort the callback session (reconcile or resolve). }
  193.                             { (resolver : undo all changes). }
  194.   dscbrMERGE         = 3;   { Merge the changes  (resolver : 'simple' merge) }
  195.                             { (reconcile : update original. Keep change). }
  196. { Resolving only }
  197.   dscbrAPPLY         = 4;   { Overwrite the current record with new values. }
  198.   dscbrIGNORE        = 5;   { Ignore the update request. Don't report error. }
  199.  
  200. { Reconcile only }
  201.   dscbrCORRECT       = 4;   { Overwrite change with new values. }
  202.   dscbrCANCEL        = 5;   { Cancel change (remove from delta). }
  203.   dscbrREFRESH       = 6;   { Update original record. Cancel change. }
  204.  
  205. type
  206.   dsCBRType = Integer;
  207.   pdsCBRType = ^dsCBRType;
  208.  
  209. //
  210. type
  211.   DSErrorCategory = type Integer;         // Resolver Error Category
  212. const
  213.     dsErrCategoryOTHER          = $0001;
  214.     dsErrCategoryDATALOSS       = $0002;
  215.     dsErrCategoryNOTFOUND       = $2200;
  216.     dsErrCategoryINTEGRITY      = $2600;
  217.     dsErrCategoryLOCKCONFLICT   = $2800;
  218.     dsErrCategorySECURITY       = $2900;
  219.  
  220. // Reconcile-callback
  221. type
  222.   pfDSReconcile = function(
  223.     iClientData   : Integer;  //
  224.     iRslt         : Integer;  // Result of previous callback. If set, the previuos parameters are repeated.
  225.     iAction       : DSAttr;   // Update request Insert/Modify/Delete
  226.     iResponse     : dsCBRType; // Resolver response (used only by Reconcile).
  227.     iErrCode      : Integer;  // Native error-code, (BDE or ..)
  228.     pErrMessage   : PChar;    // Native errormessage, if any (otherwise NULL)
  229.     pErrContext   : PChar;    // 1-level error context, if any (otherwise NULL)
  230.     pRecUpd       : PByte;    // Record that failed update
  231.     pRecOrg       : PByte;    // Original record, if any
  232.     pRecConflict  : PByte     // Conflicting error, if any
  233.   ): dsCBRType; stdcall;
  234.  
  235.  
  236. type
  237.  
  238. { IDSBase }
  239.  
  240.   IDSBase = interface(IUnknown)
  241.     ['{9E8D2F82-591C-11D0-BF52-0020AF32BD64}']
  242.  
  243.     function Create(                // Create empty dataset
  244.         iFields  : Integer;
  245.         pFldDes  : pDSFLDDesc;
  246.         pszName  : PChar
  247.     ): DBIResult; stdcall;
  248.  
  249.     function AddField(
  250.         pFldDes  : pDSFLDDesc
  251.     ): DBIResult; stdcall;
  252.  
  253.     function AppendData(            // Appends data packet to dataset.
  254.         pPacket  : PVarArray;       // Data packet
  255.         bEof     : Bool             // If True, this is last packet
  256.     ): DBIResult; stdcall;
  257.  
  258.     function GetOptParameter(       // Returns optional parameter (unknown to dataset)
  259.         iNo      : Integer;         // Number 1..iOptAttr
  260.         iFldNo   : Integer;         // 0 if not field attribute
  261.         ppName   : Pointer;          // returns ptr to name
  262.     var piType   : Integer;         // returns type
  263.     var piLen    : Integer;         // returns length
  264.     var ppValue  : PChar            // returns ptr to value
  265.     ): DBIResult; stdcall;
  266.  
  267.     function AddOptParameter(       // Adds optional parameter to dataset
  268.         iFldNo   : Integer;         // 0 if not field attribute
  269.         pszAttr  : PChar;           // ptr to name
  270.         iType    : Integer;         // type
  271.         iLen     : Integer;         // length
  272.         pValue   : Pointer          //  ptr to value
  273.     ): DBIResult; stdcall;
  274.  
  275.     function GetProps(
  276.     var  p1 : DSProps
  277.     ): DBIResult; stdcall;
  278.  
  279.     function GetFieldDescs(
  280.         p1  : pDSFLDDesc
  281.     ): DBIResult; stdcall;
  282.  
  283.     function GetIndexDescs(
  284.         p1: PDSIDXDesc
  285.     ): DBIResult; stdcall;
  286.  
  287.     function GetDelta(              // Extract delta from ds, as delta
  288.     out DsDelta: IDSBase           // Returns dataset (must be cast to pDSBASE)
  289.     ): DBIResult; stdcall;
  290.  
  291.     function StreamDS(              // Create data packet from the dataset
  292.     out ppPacket: PVarArray         // Return data packet
  293.     ): DBIResult; stdcall;
  294.  
  295.     function AcceptChanges: DBIResult; stdcall; // Accept all current changes (cannot be undone).
  296.  
  297.     function CreateIndex(           // Create, and add an index
  298.     const IdxDesc  : DSIDXDesc
  299.     ): DBIResult; stdcall;
  300.  
  301.     function RemoveIndex(           // Remove index of given name
  302.         pszName  : PChar
  303.     ): DBIResult; stdcall;
  304.  
  305.     function GetErrorString(
  306.         iErrCode  : DBIResult;
  307.         pString   : PChar
  308.     ): DBIResult; stdcall;
  309.  
  310.     function GetProp(               // Get property
  311.         eProp      : DSProp;
  312.     var iPropValue : Integer
  313.     ): DBIResult; stdcall;
  314.  
  315.     function SetProp(               // Set property
  316.         eProp      : DSProp;
  317.         iPropValue : Integer
  318.     ): DBIResult; stdcall;
  319.  
  320.     function SetFieldCalculation(   // Register fieldcalculation on this field
  321.         iClientData  : Integer;
  322.         pfCalc       : pfDSCalcField  // Callback function, NULL to remove
  323.     ): DBIResult; stdcall;
  324.  
  325.     function Reconcile(
  326.         pDeltaPacket  : PVarArray;    // Delta data packet
  327.         pErrorPacket  : PVarArray;    // NULL if all changes accepted
  328.         iClientData   : Integer;
  329.         pfReconcile   : pfDSReconcile // Callback-fn (called for each error)
  330.     ): DBIResult; stdcall;
  331.  
  332.     function AddAggregate( 
  333.         pcanExpr     : Pointer; 
  334.         iLen         : Integer;          // Length of canexpr
  335.         pDsFldDesc   : pDSFLDDesc;       // returns field-descriptor for aggregate
  336.         phAggregate  : phDSAggregate       // returns aggregate handle
  337.     ): DBIResult; stdcall;
  338.   
  339.     function DropAggregate( 
  340.         hAggregate  : hDSAggregate
  341.     ): DBIResult; stdcall;
  342.   
  343.     function GetAggregateValue( 
  344.         hAggregate  : hDSAggregate; 
  345.         pValue      : PByte               // returns aggregate value
  346.     ): DBIResult; stdcall;
  347.   
  348.     function Refresh( 
  349.         pNewPacket   : PVarArray;          // New updated packet
  350.         iClientData  : Integer;
  351.         pfReconcile  : pfDSReconcile       // Callback for resolving conflicts
  352.     ): DBIResult; stdcall;
  353.   
  354.   end;
  355.  
  356. { IDSCursor }
  357.  
  358.   IDSCursor = interface(IUnknown)
  359.     ['{9E8D2F84-591C-11D0-BF52-0020AF32BD64}']
  360.  
  361.     function InitCursor(            // Associate Cursor with a DataSet
  362.        DataSet: IDSBase
  363.     ): DBIResult; stdcall;
  364.  
  365.     function CloneCursor(           // Clone cursor from cursor
  366.        Cursor: IDSCursor
  367.     ): DBIResult; stdcall;
  368.  
  369.     function GetCursorProps(        // Get cursor properties
  370.     var p1: DSProps
  371.     ): DBIResult; stdcall;
  372.  
  373.     function GetIndexDescs(
  374.         bCurrentOnly  : Bool;       // Only return 'current' indexdesc, otherwise all
  375.     var IdxDesc       : DSIDXDesc
  376.     ): DBIResult; stdcall;
  377.  
  378.     function GetFieldDescs(         // Get field descriptors
  379.         p1  : pDSFLDDesc
  380.     ): DBIResult; stdcall;
  381.  
  382.     function GetCurrentRecord(      // Return record at current cursorposition
  383.         pRecBuf  : Pointer
  384.     ): DBIResult; stdcall;
  385.  
  386.     function GetRecordBlock(        // Return block of records
  387.         piRecs   : PULONG;
  388.         pRecBuf  : Pointer
  389.     ): DBIResult; stdcall;
  390.  
  391.     function GetCurrentBookMark(    // Get bookmark for current position
  392.         pBookMark  : Pointer
  393.     ): DBIResult; stdcall;
  394.  
  395.     function GetSequenceNumber(     // Get Sequence number of current position
  396.     var iSeq  : Integer
  397.     ): DBIResult; stdcall;
  398.  
  399.     function GetRecordAttribute(    // Get record attribute of current position
  400.     var Attr  : DSAttr
  401.     ): DBIResult; stdcall;
  402.  
  403.     function GetRecordCount(        // Number of records in active view
  404.     var iRecs  : Integer
  405.     ): DBIResult; stdcall;
  406.  
  407.     { Navigation }
  408.  
  409.     function MoveToBOF: DBIResult; stdcall; // Set to beginning of table (BOF)
  410.     function MoveToEOF: DBIResult; stdcall; // Set to end of table (EOF)
  411.     function MoveRelative(i: Integer): DBIResult; stdcall;
  412.     function MoveToSeqNo(i: Integer): DBIResult; stdcall;
  413.     function MoveToBookMark(
  414.       pBookMark: Pointer): DBIResult; stdcall;
  415.     function MoveToKey(
  416.         SearchCond  : DBISearchCond;
  417.         iFields     : Integer;
  418.         iPartLen    : Integer;
  419.         pRecBuf     : Pointer): DBIResult; stdcall;
  420.  
  421.  
  422.     function CompareBookMarks(      // Compare two bookmark (positions) -1, 0, 1
  423.         pBookMark1  : Pointer;
  424.         pBookMark2  : Pointer;
  425.     var iCmp        : Integer
  426.     ): DBIResult; stdcall;
  427.  
  428.     function ExtractKey(            // Extract key from record
  429.         pRecBuf  : Pointer;
  430.         pKeyBuf  : Pointer
  431.     ): DBIResult; stdcall;
  432.  
  433.     function GetRecordForKey(       // Return (first) record with given key
  434.         iFields   : Integer;
  435.         iPartLen  : Cardinal;
  436.         pKey      : Pointer;
  437.         pRecBuf   : Pointer
  438.     ): DBIResult; stdcall;
  439.  
  440.     function GetField(              // Extract field value from record buffer
  441.         pRecBuf   : Pointer;
  442.         iFieldNo  : Integer;
  443.         pFldBuf   : Pointer;
  444.     var bBlank    : Bool            // Returns TRUE/FALSE if blank
  445.     ): DBIResult; stdcall;
  446.  
  447.     function PutField(              // Put field value into record buffer
  448.         pRecBuf   : Pointer;
  449.         iFieldNo  : Integer;
  450.         pFldBuf   : Pointer         // If NULL, adds a blank value
  451.     ): DBIResult; stdcall;
  452.  
  453.     { Blob functions }
  454.  
  455.     function GetBlobLen(            // Return length of blob
  456.         pRecBuf   : Pointer;
  457.         iFieldNo  : Integer;
  458.     var iLength   : Integer
  459.     ): DBIResult; stdcall;
  460.  
  461.     function GetBlob(               // Return blob
  462.         pRecBuf   : Pointer;
  463.         iFieldNo  : Integer;
  464.         iOffSet   : Integer;        // Starting position
  465.         pBuf      : Pointer;
  466.     var iLength   : Integer         // No of bytes to be read/ returns number read
  467.     ): DBIResult; stdcall;
  468.  
  469.     function PutBlob(
  470.         pRecBuf   : Pointer;
  471.         iFieldNo  : Integer;
  472.         iOffSet   : Integer;        // Starting position
  473.         pBuf      : Pointer;
  474.         iLength   : Integer
  475.     ): DBIResult; stdcall;
  476.  
  477.     { Update functions }
  478.  
  479.     function InitRecord(            // Initialize record buffer (for insertion)
  480.         pRecBuf  : Pointer
  481.     ): DBIResult; stdcall;
  482.  
  483.     function DeleteRecord: DBIResult; stdcall; // Delete current record
  484.  
  485.     function ModifyRecord(          // Modify current record
  486.         pRecBuf  : Pointer
  487.     ): DBIResult; stdcall;
  488.  
  489.     function InsertRecord(          // Insert new record
  490.         pRecBuf  : Pointer
  491.     ): DBIResult; stdcall;
  492.  
  493.     function UndoLastChange(        // Undo last update
  494.         bFollowChange  : Bool
  495.     ): DBIResult; stdcall;
  496.  
  497.     function AddFilter(             // Add a canexpr-filter to this cursor
  498.         pcanExpr  : Pointer;        // Can expr
  499.         iLen      : Integer;        // Length of canexpr
  500.     var hFilter   : hDSFilter
  501.     ): DBIResult; stdcall;
  502.  
  503.     function DropFilter(            // Drop a filter
  504.        hFilter  : hDSFilter
  505.     ): DBIResult; stdcall;
  506.  
  507.     function SetRange(              // Set a range on a cursor
  508.         iFields    : Integer;
  509.         pKey1      : Pointer;
  510.         bKey1Incl  : Bool;
  511.         pKey2      : Pointer;
  512.         bKey2Incl  : Bool
  513.     ): DBIResult; stdcall;
  514.  
  515.     function DropRange: DBIResult; stdcall; // Remove current range
  516.  
  517.     function SortOnFields(          // Sort on fields
  518.         iFields    : Integer;
  519.         piFields   : PInteger;      // NULL -> all fields
  520.         pDescending: PBool;         // NULL -> all ascending
  521.         pCaseInsensitive: PBool     // NULL -> all case-sensitive
  522.     ): DBIResult; stdcall;
  523.  
  524.     function UseIndexOrder(         // Switch to index order
  525.         pszName  : PChar
  526.     ): DBIResult; stdcall;
  527.  
  528.     function SetNotifyCallBack(     // Called when posting changes to dataset
  529.         iClientData  : Integer;
  530.         pfCallBack   : pfCHANGECallBack   // Call back fn being registered
  531.     ): DBIResult; stdcall;
  532.  
  533.     function AddFilterCallBack(     // Add a canexpr-filter to this cursor
  534.         iClientData  : Integer;     // Client supplied data
  535.         pfFilter     : pfDSFilter;  // ptr to filter function
  536.     var hFilter      : hDSFilter
  537.     ): DBIResult; stdcall;
  538.  
  539.     function VerifyField(           // Verify if field value is valid
  540.         iFieldNo  : Integer;
  541.         pFldBuf   : Pointer
  542.     ): DBIResult; stdcall;
  543.  
  544.     function GetProp(               // Get property
  545.         eProp       : CURProp;
  546.     var iPropValue  : Integer
  547.     ): DBIResult; stdcall;
  548.  
  549.     function RevertRecord: DBIResult; stdcall; // Restore current record
  550.  
  551.   end;
  552.  
  553. const
  554.   CLSID_DSBase: TGUID   = '{9E8D2F81-591C-11D0-BF52-0020AF32BD64}';
  555.   CLSID_DSCursor: TGUID = '{9E8D2F83-591C-11D0-BF52-0020AF32BD64}';
  556.  
  557. implementation
  558.  
  559.  
  560. end.
  561.